// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.ActionLogVMs;

namespace WalkingTec.Mvvm.Mvc.Admin.Controllers
{
	[Area("_Admin")]
	[ActionDescription("MenuKey.ActionLog")]
	[FixConnection(CsName = "defaultlog")]
	public class ActionLogController : BaseController
	{
		[ActionDescription("Sys.Search")]
		public IActionResult Index()
		{
			var vm = Wtm.CreateVM<ActionLogListVM>();
			return PartialView(vm);
		}

		[ActionDescription("Sys.Search")]
		[HttpPost]
		public string Search(ActionLogSearcher searcher)
		{
			var vm = Wtm.CreateVM<ActionLogListVM>(passInit: true);
			if (ModelState.IsValid)
			{
				vm.Searcher = searcher;
				return vm.GetJson(false);
			}
			else
			{
				return vm.GetError();
			}
		}
		[Public]
		public string Search()
		{
			var vm = Wtm.CreateVM<ActionLogListVM>(passInit: true);
			vm.Searcher = new ActionLogSearcher();
			return vm.GetJson(false);

		}

		[HttpGet]
		[ActionDescription("Sys.Details")]
		public IActionResult Details(string id)
		{
			var vm = Wtm.CreateVM<ActionLogVM>(id);
			return PartialView(vm);
		}

		[ActionDescription("Sys.Export")]
		[HttpPost]
		public IActionResult ExportExcel(ActionLogListVM vm)
		{
			return vm.GetExportData();
		}

		[HttpPost]
		[ActionDescription("Sys.BatchDelete")]
		public ActionResult BatchDelete(string[] IDs)
		{
			var vm = Wtm.CreateVM<ActionLogBatchVM>(Ids: IDs);
			return PartialView(vm);
		}

		[HttpPost]
		[ActionDescription("Sys.BatchDelete")]
		public ActionResult DoBatchDelete(ActionLogBatchVM vm, IFormCollection nouse)
		{
			if (!ModelState.IsValid || !vm.DoBatchDelete())
			{
				return PartialView("BatchDelete", vm);
			}
			else
			{
				return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
			}
		}

	}
}
